﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Drawing.Drawing2D;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using AnguaRPGEngine.Library.Systems;

namespace AnguaRPGEngine.Library.Forms
{
    public partial class JoinForm : Form
    {
        public string HostIP
        {
            get
            {
                return txtHostIP.Text;
            }
        }
        public int HostPort
        {
            get
            {
                try
                {
                    return (int)nudHostPort.Value;
                }
                catch
                {
                    return 0;
                }
            }
        }
        public string Password
        {
            get
            {
                return txtHostPassword.Text;
            }
        }
        public JoinForm()
        {
            InitializeComponent();
        }
        const int WM_NCHITTEST = 0x0084;
        const int HTCLIENT = 1;
        const int HTCAPTION = 2;
        protected override void WndProc(ref Message m)
        {
            base.WndProc(ref m);
            switch (m.Msg)
            {
                case WM_NCHITTEST:
                    if (m.Result == (IntPtr)HTCLIENT)
                    {
                        m.Result = (IntPtr)HTCAPTION;
                    }
                    break;
            }
        }
        protected override void OnPaint(PaintEventArgs e)
        {
            base.OnPaint(e);
            e.Graphics.FillRectangle(new LinearGradientBrush(new Point(0, 0), new Point(this.Width, 15), Color.DarkBlue, Color.Blue), new Rectangle(0, 0, this.Width, 15));
            e.Graphics.DrawLine(new Pen(new SolidBrush(Color.DarkGray), 1f), new Point(0, 16), new Point(this.Width, 16));
            e.Graphics.DrawString(this.Text, this.Font, new SolidBrush(Color.White), new PointF(0, 0));

        }
        protected override CreateParams CreateParams
        {
            get
            {
                CreateParams cp = base.CreateParams;
                cp.Style |= 0x40000;

                return cp;
            }
        }

        private void btnLoad_Click(object sender, EventArgs e)
        {
            using (OpenFileDialog ofd = new OpenFileDialog())
            {
                ofd.Title = "Open Host File";
                ofd.Filter = "Host File (*.mhf)|*.mhf";
                if (ofd.ShowDialog() == System.Windows.Forms.DialogResult.OK)
                {
                    HostFile hf = Serializer<HostFile>.DeserializeFromFile(ofd.FileName);
                    if (hf != null)
                    {
                        txtHostIP.Text = hf.HostIP;
                        nudHostPort.Value = hf.HostPort;
                        txtHostPassword.Text = hf.HostPassword;
                    }
                }
            }
        }
    }
}
